$(function(){
 

  //保存选择的属性
  var params=[];
  setcurrentattrs=function(basepath,obj,id,name){
    $("a[name='attr"+id+"']").each(function(k,v){
      $(v).parent().attr("class","");
      if(name==$(v).text()){
        $(v).parent().attr("class","select-all selected");
      }
    });
    var tk=[];
    $.each(params,function(k,v){
      tk=v.split(":");
      if(tk[1]==id){
        params.splice($.inArray(k,params),1);
      }
    });
    params.push(name+":"+id);
    var strs=params.join(",")
    if(window.localStorage){
      localStorage.setItem("attrs",strs);
    }
    //跳转请求过滤结果
    var navid=$.query.get("navid");
    if(navid!=""){
      window.location.href=basepath+"/goods/fitlerGoodsByAttrs.action?attrs="+strs+"&navid="+navid;
    }else{
      window.location.href=basepath+"/goods/fitlerGoodsByAttrs.action?attrs="+strs+"&navid=";
    }
    
  },
  rebindcurrentattrs=function(){
    if(window.localStorage){
      var strs=localStorage.getItem("attrs");
      var array=strs.split(",");
      params=$.unique(array);
    }
    var attrid;
    var tempattrs=[];
    
    $("ul li dl dd a").each(function(k,v){
      for(var i=0;i<params.length;i++){
        tempattrs=params[i].split(":");
        attrid=tempattrs[1];
        if($(v).attr('id')=='attr'+attrid){
          var t=$(v).text();
          if(t=="全部"){
            $(v).parent().attr("class","");
          }
          if(t==tempattrs[0]){
            $(v).parent().attr("class","select-all selected");
          }
        }
      }
    });
  },
  rebindcurrentattrs();






});